package com.appwoo.txtws.component;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import com.appwoo.txtws.bean.PhoneBean;
import java.io.PrintStream;
import java.util.ArrayList;

public class PhoneHelper extends SQLiteOpenHelper
{
  private static final int version = 10;
  private SQLiteDatabase mdb = null;

  public PhoneHelper(Context paramContext)
  {
    super(paramContext, "db_phone", null, 10);
  }

  public void addPhones(ArrayList<PhoneBean> paramArrayList)
  {
    if (this.mdb == null)
      this.mdb = getWritableDatabase();
    try
    {
      int i = paramArrayList.size();
      for (int j = 0; ; j++)
      {
        if (j >= i)
        {
          return;
          this.mdb.close();
          this.mdb = getWritableDatabase();
          break;
        }
        PhoneBean localPhoneBean = (PhoneBean)paramArrayList.get(j);
        String str = "insert into t_phones(pno,pname,ptype,isdel,udtime) values ('" + localPhoneBean.getPno() + "'," + "'" + localPhoneBean.getPname() + "'," + "'" + localPhoneBean.getPtype() + "'," + "'" + localPhoneBean.getIsdel() + "'," + "'" + localPhoneBean.getUdtime() + "')";
        System.out.println(str);
        this.mdb.execSQL(str);
      }
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
      return;
    }
    finally
    {
      if (this.mdb != null)
        this.mdb.close();
    }
  }

  public void clearData()
  {
    try
    {
      if (this.mdb == null)
        this.mdb = getReadableDatabase();
      if (!this.mdb.isOpen())
        this.mdb = getWritableDatabase();
      this.mdb.delete("t_phones", null, null);
      return;
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
      return;
    }
    finally
    {
      if (this.mdb != null)
        this.mdb.close();
    }
  }

  public void delData()
  {
    try
    {
      if (this.mdb == null)
        this.mdb = getReadableDatabase();
      if (!this.mdb.isOpen())
        this.mdb = getWritableDatabase();
      this.mdb.delete("t_phones", "isdel = '1'", null);
      return;
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
      return;
    }
    finally
    {
      if (this.mdb != null)
        this.mdb.close();
    }
  }

  public ArrayList<PhoneBean> getPhoneList(String paramString)
  {
    ArrayList localArrayList = new ArrayList();
    int i = 0;
    try
    {
      if (this.mdb == null)
        this.mdb = getReadableDatabase();
      if (!this.mdb.isOpen())
        this.mdb = getReadableDatabase();
      Cursor localCursor;
      if (paramString.equals(""))
        localCursor = this.mdb.query("t_phones", null, "isdel='0'", null, null, null, null);
      while (true)
        if (!localCursor.moveToNext())
        {
          localCursor.close();
          Logger.d("xjf", "getPhoneList()--[count]==>" + i);
          return localArrayList;
          localCursor = this.mdb.query("t_phones", null, "isdel='0' and ptype = '" + paramString + "' ", null, null, null, null);
          i = 0;
        }
        else
        {
          PhoneBean localPhoneBean = new PhoneBean();
          localPhoneBean.setPno(localCursor.getString(localCursor.getColumnIndex("pno")));
          localPhoneBean.setPname(localCursor.getString(localCursor.getColumnIndex("pname")));
          localPhoneBean.setPtype(localCursor.getString(localCursor.getColumnIndex("ptype")));
          localPhoneBean.setIsdel(localCursor.getString(localCursor.getColumnIndex("isdel")));
          localPhoneBean.setUdtime(localCursor.getString(localCursor.getColumnIndex("udtime")));
          localArrayList.add(localPhoneBean);
          i++;
        }
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
      return localArrayList;
    }
    finally
    {
      if (this.mdb != null)
        this.mdb.close();
    }
  }

  public int isPhoneNull()
  {
    int i = 0;
    try
    {
      SQLiteDatabase localSQLiteDatabase = this.mdb;
      i = 0;
      if (localSQLiteDatabase == null)
        this.mdb = getReadableDatabase();
      boolean bool = this.mdb.isOpen();
      i = 0;
      if (!bool)
        this.mdb = getReadableDatabase();
      Cursor localCursor = this.mdb.query("t_phones", null, null, null, null, null, null);
      while (true)
      {
        if (!localCursor.moveToNext())
        {
          localCursor.close();
          Logger.d("xjf", "isPhoneNull()--[count]==>" + i);
          return i;
        }
        i++;
      }
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
      return i;
    }
    finally
    {
      if (this.mdb != null)
        this.mdb.close();
    }
  }

  public void onCreate(SQLiteDatabase paramSQLiteDatabase)
  {
    paramSQLiteDatabase.execSQL("CREATE TABLE IF NOT EXISTS t_phones(_id INTEGER PRIMARY KEY AUTOINCREMENT,pno TEXT, pname TEXT, ptype TEXT, isdel TEXT, udtime TEXT );");
  }

  public void onUpgrade(SQLiteDatabase paramSQLiteDatabase, int paramInt1, int paramInt2)
  {
    try
    {
      paramSQLiteDatabase.execSQL("drop table t_phones");
      label6: paramSQLiteDatabase.execSQL("CREATE TABLE IF NOT EXISTS t_phones(_id INTEGER PRIMARY KEY AUTOINCREMENT,pno TEXT, pname TEXT, ptype TEXT, isdel TEXT, udtime TEXT );");
      return;
    }
    catch (Exception localException)
    {
      break label6;
    }
  }

  public String queryMaxTime()
  {
    Object localObject1 = "1900-01-01 08:00:00";
    try
    {
      if (this.mdb == null)
        this.mdb = getReadableDatabase();
      if (!this.mdb.isOpen())
        this.mdb = getReadableDatabase();
      Cursor localCursor = this.mdb.rawQuery("select max(udtime) from t_phones", null);
      while (true)
      {
        if (!localCursor.moveToNext())
        {
          localCursor.close();
          if (this.mdb != null)
            this.mdb.close();
          Logger.d("xjf", "[maxUdTime]==>" + (String)localObject1);
          if (localObject1 == null)
            localObject1 = "1900-01-01 08:00:00";
          return localObject1;
        }
        String str = localCursor.getString(0);
        localObject1 = str;
      }
    }
    catch (Exception localException)
    {
      while (true)
      {
        localException.printStackTrace();
        if (this.mdb != null)
          this.mdb.close();
        Logger.d("xjf", "[maxUdTime]==>" + (String)localObject1);
      }
    }
    finally
    {
      if (this.mdb != null)
        this.mdb.close();
      Logger.d("xjf", "[maxUdTime]==>" + (String)localObject1);
    }
  }

  public void updatePhones(ArrayList<PhoneBean> paramArrayList)
  {
    try
    {
      if (this.mdb == null)
        this.mdb = getReadableDatabase();
      if (!this.mdb.isOpen())
        this.mdb = getWritableDatabase();
      int i = paramArrayList.size();
      new ContentValues().put("isdel", "1");
      for (int j = 0; ; j++)
      {
        if (j >= i)
          return;
        String str = ((PhoneBean)paramArrayList.get(j)).getPno();
        this.mdb.execSQL("update t_phones set isdel=?  where pno=?", new Object[] { "1", str });
      }
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
      return;
    }
    finally
    {
      if (this.mdb != null)
        this.mdb.close();
    }
  }
}

/* Location:           C:\Documents and Settings\Administrator\classes_dex2jar.jar
 * Qualified Name:     com.appwoo.txtws.component.PhoneHelper
 * JD-Core Version:    0.6.2
 */